package com.wgts.wgts.mvp.view.activity.otherhomepage;

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wgts.wgts.R;
import com.wgts.wgts.base.BaseFragment;
import com.wgts.wgts.base.LazyBaseFragment;
import com.wgts.wgts.localbean.LocalAppModleResult;
import com.wgts.wgts.mvp.view.activity.homeclasschildactivity.ShopClassChildActivity;
import com.wgts.wgts.netmodle.resp.AppModleEntity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/*
 *
 *
 *   data:2018/9/1716:55
 *
 */public class ShopClassFragment extends LazyBaseFragment {
    @BindView(R.id.view_page_recycle)
    RecyclerView viewPageRecycle;
    Unbinder unbinder;
    private static final String recycleData = "recycleData";
    private ShopClassRecycleAdapter adapter;
    private List<LocalAppModleResult> list = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        if (bundle != null) {
            list = bundle.getParcelableArrayList(recycleData);
        }
        View view = inflater.inflate(R.layout.shop_class_fragment, viewGroup, false);
        unbinder = ButterKnife.bind(this, view);
        initView();
        return view;
    }

    @Override
    public void init() {

    }

    private void initView(){
        adapter = new ShopClassRecycleAdapter(getActivity(), list);
        viewPageRecycle.setLayoutManager(new GridLayoutManager(getActivity(), 4, GridLayoutManager.VERTICAL, false));
        viewPageRecycle.setAdapter(adapter);
        adapter.setOnItemClickListener(new ShopClassRecycleAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Intent intent = new Intent(getActivity(), ShopClassChildActivity.class);
                intent.putExtra("id", list.get(position).id);
                intent.putExtra("name", list.get(position).name);
                startActivity(intent);
            }
        });
    }

    public static ShopClassFragment getShopClassFragment(List<LocalAppModleResult> data) {
        ShopClassFragment classFragment = new ShopClassFragment();
        Bundle bundle = new Bundle();
        bundle.putParcelableArrayList(recycleData, (ArrayList<? extends Parcelable>) data);
        classFragment.setArguments(bundle);
        return classFragment;
    }

    @Override
    protected void loadData() {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
